package com.zzh.test;

import java.io.File;
import java.io.FileInputStream; 
import java.io.IOException;
import java.io.InputStream;

import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.extractor.WordExtractor;
import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.junit.Test;

/**
 * @author zzh
 * @description 读取各种word文档
 * @date 2017年2月6日 下午4:02:14
 */
public class readWord {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		// readDoc2003();
		readDoc2007();

	}

	/**
	 * docx
	 */
	@Test
	private static void readDoc2007() {
		String path = "C:/cv/3-1/51job_葛冶(69755810).doc";
		path = "C:/cv/123.docx";
		InputStream in = null;
		try {
			in = new FileInputStream(path);
			XWPFDocument doc = new XWPFDocument(in);
			XWPFWordExtractor extractor = new XWPFWordExtractor(doc);
			String text = extractor.getText();
			System.out.println(text);

		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	/**
	 * doc
	 */
	@Test
	private static void readDoc2003() {
		// String filepath="C:/cv/Java_zzf15.doc";
		String filepath = "C:/cv/3-1/51job_葛冶(69755810).doc";
		try {
			InputStream is = new FileInputStream(filepath);
			HWPFDocument doc = new HWPFDocument(is);
			System.out.println(doc.getText());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/**
	 * doc
	 */
	@Test
	public void test() {
		try {
			InputStream is = new FileInputStream(new File("C:/cv/3-1/51job_葛冶(69755810).doc"));
			WordExtractor ex = new WordExtractor(is);
			String text2003 = ex.getText();
			System.out.println(text2003);
		}   catch (IOException e) {
			e.printStackTrace();
		}
	}

}
